🎨 Graph M-Coloring Solver (Backtracking)

Input Parameters

Graph M-Coloring Challenge

Given a graph (represented by an adjacency matrix) and a number of available colors ($m$), the task is to find a way to color all vertices such that **no two adjacent vertices share the same color**.

Input and Output Format

  • **Input:** Adjacency matrix (V x V) followed by the number of colors ($m$).
  • **Output:** A space-separated list of the assigned colors for each vertex (1 to $V$), or the string "Solution does not exist".

Sample Input/Output

Sample 1 (Success):
4
0 1 1 1
1 0 1 0
1 1 0 1
1 0 1 0
3

Output:
1 2 3 2
                
Sample 3 (Failure):
4
0 1 0 1
1 0 0 1
0 0 0 0
1 1 0 0
2

Output:
Solution does not exist